﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Web.Services;
using System.IO;

public partial class Admin_CatProduct : System.Web.UI.Page
{
    CategoryController categoryController = new CategoryController();
    protected void Page_Load(object sender, EventArgs e)
    {
        grvCatProduct.DataSource = categoryController.getAllCategory();
        grvCatProduct.DataBind();

        if (grvCatProduct.Rows.Count > 0)
        {
            grvCatProduct.UseAccessibleHeader = true;
            grvCatProduct.HeaderRow.TableSection = TableRowSection.TableHeader;
        }  
    }
    [WebMethod]
    public static string deleteCatProduct(int category_id)
    {
        CategoryController categoryController = new CategoryController();
        List<CategoryImageProduct> list = categoryController.getCategoryImageProduct(category_id);
        string fileUpload = HttpContext.Current.Server.MapPath("~/");
        foreach (var item in list)
        {
            categoryController.deleteImageCatProduct(item.Category_image_id);

            File.Delete(fileUpload + item.Image);
        }
        if (categoryController.Delete(category_id) > 0)
        {
            return "true";
        }
        else
        {
            return "false";
        }
    }
}